import java.util.concurrent.ThreadLocalRandom;

public class demo1 {
    private static final int size=10_000_000;
    private static final int min=1;
    private static final int max=100;
    private static int result=0;
    public static void main(String[] args) {
        int[] nums=new int[size];
        ThreadLocalRandom random=ThreadLocalRandom.current();//随机数生成
        for(int i=0;i<size;i++){
            nums[i]=random.nextInt(min,max);
        }

        Thread t=new Thread(()->{//计算偶数下标和
            int sum=0;
            for(int i=0;i<size;i+=2){
                sum+=nums[i];
            }
            result+=sum;
        });
        Thread t1=new Thread(()->{//计算奇数下标和
            int sum=0;
            for(int i=1;i<size;i+=2){
                sum+=nums[i];
            }
            result+=sum;
        });
        t.start();
        t1.start();
        try {
            t.join();
            t1.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(result);
    }
}
